package com.example.mianshi;

import java.io.*;

public class ReadFileThread implements Runnable {

    private DoWorkTemplate template;

    private File file;

    public ReadFileThread(DoWorkTemplate template,File file){
        this.template = template;
        this.file = file;
    }

    @Override
    public void run() {
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
            String line = "";
            String[] fileArrs = null;
            while((line=reader.readLine())!=null){
                if(line == ""){
                    continue;
                }
                fileArrs =line.trim().split(",");
                MFile mFile = FileFactory.getInstance().createMFile(fileArrs);
                template.queue.add(mFile);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            if(reader != null){
                try {
                    reader.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                reader = null;
            }
            System.out.println("==========="+template.countDownLatch.getCount());
            template.countDownLatch.countDown();
        }
    }
}
